package com.yuantu.judiciary.utils;


import com.yuantu.judiciary.common.CodeEnum;
import com.yuantu.judiciary.exception.ServiceException;

import java.util.Objects;

/**
 * 断言校验工具类
 *
 * @author syw
 * @since 2023-06-08
 **/
public class AssertUtil {
    public AssertUtil() {
    }

    public static void assertTrue(boolean bool, CodeEnum errorEnum) {
        if (!bool) {
            throw new ServiceException(errorEnum.getCode(), errorEnum.getMessage());
        }
    }

    public static void assertTrue(boolean bool, int errCode, String falseMessage) {
        if (!bool) {
            throw new ServiceException(errCode, falseMessage);
        }
    }

    public static void assertNotNull(Object entity, CodeEnum errorEnum) {
        if (Objects.isNull(entity)) {
            throw new ServiceException(errorEnum.getCode(), errorEnum.getMessage());
        }
    }

    public static void assertNotNull(Object entity, int errCode, String falseMessage) {
        if (Objects.isNull(entity)) {
            throw new ServiceException(errCode, falseMessage);
        }
    }

    public static void assertNull(Object entity, CodeEnum errorEnum) {
        if (!Objects.isNull(entity)) {
            throw new ServiceException(errorEnum.getCode(), errorEnum.getMessage());
        }
    }

    public static void assertNull(Object entity, int errCode, String falseMessage) {
        if (!Objects.isNull(entity)) {
            throw new ServiceException(errCode, falseMessage);
        }
    }
}

